package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

/**
 * @program: sky-take-out
 * @description:
 * @author: lydms
 * @create: 2024-02-29 15:05
 **/


@RestController("adminShopController")
@Slf4j
@Api(tags = "店铺管理")
@RequestMapping("/admin/shop")
public class ShopController {

    public static final String KEY = "SHOP_STATUS";

    @Autowired
    public RedisTemplate redisTemplate;

    /**
     * 店铺营业状态设置
     * @param status
     * @return
     */
    @PutMapping("/{status}")
    @ApiOperation("店铺营业状态设置")
    public Result setStatus(@PathVariable Integer status){
        log.info("店铺营业状态设置为：{}",status==1?"营业中":"打样中");
        redisTemplate.opsForValue().set("SHOP_STATUS",status);
        return Result.success();
    }


    /**
     * 查询店铺营业状态
     * @return
     */
    @GetMapping("/status")
    @ApiOperation("查询店铺营业状态")
    public Result<Integer> getStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get("SHOP_STATUS");
        log.info("店铺营业状态设置为：{}",status==1?"营业中":"打样中");
        return Result.success(status);
    }
}
